package hanjia;

import suanfa.ListNode;

import java.util.HashSet;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/10-下午3:12
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode142 {

    public ListNode detectCycle(ListNode head) {
        if (head==null||head.next==null){
            return null;
        }

        HashSet<ListNode> set = new HashSet<>();
        ListNode temp=head;
        while (temp!=null){
            if (!set.add(temp)){
                return temp;
            }

            temp= temp.next;

        }
        return null;


    }
}
